function login () {

    socket.emit("login", {usernameInput: $('#usernameInput').val(), passwordInput: $('#passwordInput').val()});

    socket.on("authenticated", function (token) {
        var d = new Date(),
                daysToExist = 30;

        d.setTime(d.getTime() + (daysToExist * 24 * 60 * 60 * 1000));
        document.cookie = "token=" + token + "; expires=" + d.toGMTString();
        window.location = "/";
    });

}
function registerSubmit () {

    if (validate_contact_form() === true) {
        socket.emit("register", {usernameInput: $('#usernameInputRegister').val(), passwordInput: $('#passwordInputRegister').val(), repeatedPassword: $('#repeatedPassword').val(), emailInput: $('#emailInput').val(), betakey: $("#betakey").val()});

        socket.on("registered", function () {
            $('#usernameInput').val($('#usernameInputRegister').val());
            $('#passwordInput').val($('#passwordInputRegister').val());
            
            login();
        });
    }

}

function logout () {
    socket.emit("logout", getCookie("token"));
    document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
    location.reload();
}